home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / digest.z / digest
Encoding:
Text File  |  1997-01-22  |  4.2 KB  |  183 lines

  1. #! /usr/local/bin/zmail -F!
  2. #
  3. # Z-Mail digestifier.  Makes a folder or a list of messages into a digest.
  4. #
  5. # A "digest" is a collection of E-mail messages bundled together into a
  6. # single message for ease of redistribution.  The individual messages
  7. # in the digest are called "articles".  Each article has a small set of
  8. # essential headers (usually From:, Date:, and Subject:) and is divided
  9. # from the preceding and following articles by an "article separator"
  10. # string (usually eight hyphens, "--------").  The Z-Mail built-in command
  11. # "undigest" unpacks most digests, including those made by this script.
  12. #
  13. # Usage:
  14. #  From your shell (see below):        digestify -f mailbox
  15. #  From within zmail:    
  16. #    First:        source digestify
  17. #    Then:        digest [msg-list]
  18. #    Or:        message-selection-command | digest
  19. #
  20.  
  21. #
  22. # Set the version number of this script.
  23. #
  24. set d_version = 'digest 1.3'
  25.  
  26. #
  27. # Functions to save and restore variable state
  28. #
  29. function d_saveset() {
  30.     eval set _SET_ = '"$?'$1'"'
  31.     if $_SET_
  32.     eval set old$1 = '"$'$1'"'
  33.     else
  34.     eval unset old$1
  35.     endif
  36.     if $# > 1
  37.     set _SET_ = $1
  38.     shift
  39.     set $_SET_ = "$*"
  40.     else
  41.     unset $1
  42.     endif
  43.     unset _SET_
  44.     return 0
  45. }
  46.  
  47. function d_reset() {
  48.     eval set _SET_ = '"$?old'$1'"'
  49.     if $_SET_
  50.     eval set $1 = '"$old'$1'"'
  51.     unset old$1
  52.     endif
  53.     unset _SET_
  54.     return 0
  55. }
  56.  
  57. function digest() {
  58. #%
  59. # Z-Mail digestifier.  Makes a folder or a list of messages into a digest.
  60. #
  61. # A "digest" is a collection of E-mail messages bundled together into a
  62. # single message for ease of redistribution.  The individual messages
  63. # in the digest are called "articles".  Each article has a small set of
  64. # essential headers (usually From:, Date:, and Subject:) and is divided
  65. # from the preceding and following articles by an "article separator"
  66. # string (usually eight hyphens, "--------").  The Z-Mail built-in command
  67. # "undigest" unpacks most digests, including those made by this script.
  68. #
  69. # Usage:    digest [msg-list] [recipients]
  70. # Or:        command | digest
  71. #
  72. #  where the "command" is something that selects messages, e.g. "pick".
  73. #%
  74.     #
  75.     # Suppress any "that isn't set" messages from "unset"
  76.     #
  77.     d_saveset warning
  78.  
  79.     #
  80.     # Set up defaults
  81.     #
  82.     if $?input
  83.     msg_list $input | set digest
  84.     else
  85.     set input    # Magic
  86.     unset digest
  87.     endif
  88.     shift -m
  89.     if X$output != X
  90.     msg_list $input $output | set digest
  91.     endif
  92.     unset input        # Magic
  93.     if ! $?digest
  94.     d_reset warning
  95.     error Please specify messages to include in digest.
  96.     return -1
  97.     endif
  98.  
  99.     #
  100.     # Save everything in case the user wants it back.
  101.     #
  102.     foreach v ( \
  103.         pre_indent_str \
  104.         post_indent_str \
  105.         indent_str \
  106.         alwaysignore \
  107.         quiet \
  108.         no_expand \
  109.         edit_hdrs \
  110.         askcc \
  111.                 ) 'd_saveset $v'
  112.     if "$version" =~ *2.0*
  113.     #
  114.     # This is a real hack ....
  115.     #
  116.     echo -n "Temporarily "
  117.     saveopts /tmp/opts$$
  118.     sh "grep '^retain' /tmp/opts$$ > /tmp/rtn$$; rm /tmp/opts$$"
  119.     else
  120.     saveopts -Afqo retain /tmp/rtn$$
  121.     endif
  122.     unretain *
  123.  
  124.     #
  125.     # Prepare to form the digest.
  126.     #
  127.     set indent_str no_expand alwaysignore=include quiet=newmail
  128.     set pre_indent_str="--------"    # Insert your digest separator here
  129.     retain from date subject        # Add any other headers you want
  130.     my_hdr X-Digest-Generated-By: "$version, $d_version"
  131.     #
  132.     # Send the digest where?
  133.     #
  134.     if $#
  135.     alias DIGEST $*
  136.     else
  137.     alias DIGEST $thisfolder
  138.     d_saveset no_expand
  139.     set d_await
  140.     endif
  141.  
  142.     #
  143.     # Now do it.  All that work for a three-line operation ....
  144.     # NOTE: If you change DIGEST above, remove the "await" command here!
  145.     # Using "builtin" prevent any cmd expansion from confusing us.
  146.     #
  147.     builtin mail -UH /dev/null -I $digest -s "Digest of $thisfolder" DIGEST
  148.     if $?d_await
  149.     builtin delete $digest
  150.     builtin await -T 1
  151.     unset d_await
  152.     endif
  153.  
  154.     #
  155.     # Be neat and put everything back the way it was.
  156.     #
  157.     un_hdr X-Digest-Generated-By:
  158.     unalias DIGEST
  159.     unset indent_str no_expand alwaysignore quiet
  160.     foreach v ( \
  161.         pre_indent_str \
  162.         post_indent_str \
  163.         indent_str \
  164.         alwaysignore \
  165.         quiet \
  166.         no_expand \
  167.         edit_hdrs \
  168.         askcc \
  169.         warning \
  170.                 ) 'd_reset $v'
  171.     unretain *
  172.     source /tmp/rtn$$
  173.     sh rm /tmp/rtn$$
  174. }
  175.  
  176. #
  177. # Uncomment this part to use this file as a shell program
  178. #
  179. #if $?thisfolder
  180. #    digest
  181. #    quit
  182. #endif
  183.